test: Added --test-with-git-config option
authorJoey Hess <joeyh@joeyh.name>
Thu, 22 Sep 2022 19:58:45 +0000 (15:58 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 22 Sep 2022 19:58:45 +0000 (15:58 -0400)
Sponsored-by: Dartmouth College's DANDI project
CHANGELOG
Test.hs
Test/Framework.hs
Types/Test.hs
doc/git-annex-test.mdwn
doc/todo/specify_gitconfig_for_test_suite.mdwn

index e74887764c501864996d9be072011ba09094bdbf..172f0c14ec599c4259678a5ed4c05bc4fdb91df6 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -31,6 +31,7 @@ git-annex (10.20220823) UNRELEASED; urgency=medium
   * Improved handling of --time-limit when combined with -J
   * Fix updating git index file after getting an unlocked file 
     when annex.stalldetection is set.
+  * test: Added --test-with-git-config option.
 
  -- Joey Hess <id@joeyh.name>  Mon, 29 Aug 2022 15:03:04 -0400
 
diff --git a/Test.hs b/Test.hs
index 5ec5d8d1deab8703fd1f3e07fa9ddc9b3c6c393c..78eeef882ef83ac3305826854579fadbade5ef84 100644 (file)
--- a/Test.hs
+++ b/Test.hs
@@ -1,6 +1,6 @@
 {- git-annex test suite
  -
- - Copyright 2010-2021 Joey Hess <id@joeyh.name>
+ - Copyright 2010-202oey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -13,12 +13,12 @@ import Types.Test
 import Types.RepoVersion
 import Types.Concurrency
 import Test.Framework
-import Options.Applicative.Types
 
 import Test.Tasty
 import Test.Tasty.HUnit
 import Test.Tasty.QuickCheck
-import Options.Applicative (switch, long, short, help, internal, maybeReader, option)
+import Options.Applicative.Types
+import Options.Applicative (switch, long, short, help, internal, maybeReader, option, metavar)
 
 import qualified Data.Map as M
 import qualified Data.ByteString.Lazy.UTF8 as BU8
@@ -92,7 +92,7 @@ import qualified Utility.Gpg
 
 optParser :: Parser TestOptions
 optParser = TestOptions
-       <$> snd (tastyParser (tests 1 False True (TestOptions mempty False False Nothing mempty)))
+       <$> snd (tastyParser (tests 1 False True (TestOptions mempty False False Nothing mempty mempty)))
        <*> switch
                ( long "keep-failures"
                <> help "preserve repositories on test failure"
@@ -106,7 +106,19 @@ optParser = TestOptions
                <> short 'J'
                <> help "number of concurrent jobs"
                ))
+       <*> many (option (maybeReader parseconfigvalue)
+               ( long "test-git-config"
+               <> help "run tests with a git config set"
+               <> metavar "NAME=VALUE"
+               ))
        <*> cmdParams "non-options are for internal use only"
+  where
+       parseconfigvalue s = case break (== '=') s of
+               (_, []) -> Nothing
+               (k, v) -> Just 
+                       ( Git.Types.ConfigKey (encodeBS k)
+                       , Git.Types.ConfigValue (encodeBS (drop 1 v))
+                       )
 
 runner :: TestOptions -> IO ()
 runner opts = parallelTestRunner opts tests
index 2d8e0c6e2e49c3d894e05f3f48e27b86d873c1b4..a4f24066ed3a2aa5b37aabf1d5c4413301cabf30 100644 (file)
@@ -169,7 +169,7 @@ withtmpclonerepo' cfg a = do
        case r of
                Right () -> return ()
                Left e -> do
-                       whenM (keepFailures <$> getTestMode) $
+                       whenM (keepFailuresOption . testOptions <$> getTestMode) $
                                putStrLn $ "** Preserving repo for failure analysis in " ++ clone
                        throwM e
 
@@ -255,6 +255,13 @@ configrepo dir = indir dir $ do
        -- tell git-annex to not annex the ingitfile
        git "config" ["annex.largefiles", "exclude=" ++ ingitfile]
                "git config annex.largefiles"
+       -- set any additional git configs the user wants to test with
+       gc <- testGitConfig . testOptions <$> getTestMode
+       forM_ gc $ \case
+               (Git.Types.ConfigKey k, Git.Types.ConfigValue v) -> 
+                       git "config" [decodeBS k, decodeBS v]
+                               "git config from test options"
+               (Git.Types.ConfigKey _, Git.Types.NoConfigValue) -> noop
 
 ensuredir :: FilePath -> IO ()
 ensuredir d = do
@@ -483,15 +490,15 @@ data TestMode = TestMode
        { unlockedFiles :: Bool
        , adjustedUnlockedBranch :: Bool
        , annexVersion :: Types.RepoVersion.RepoVersion
-       , keepFailures :: Bool
-       } deriving (Show)
+       , testOptions :: TestOptions
+       }
 
 testMode :: TestOptions -> Types.RepoVersion.RepoVersion -> TestMode
 testMode opts v = TestMode
        { unlockedFiles = False
        , adjustedUnlockedBranch = False
        , annexVersion = v
-       , keepFailures = keepFailuresOption opts
+       , testOptions = opts
        }
 
 hasUnlockedFiles :: TestMode -> Bool
index b41864d256ebb171f64427de151495339b3d621e..9d0af7720834760c24c8594b401db60a94d69525 100644 (file)
@@ -11,12 +11,14 @@ import Test.Tasty.Options
 
 import Types.Concurrency
 import Types.Command
+import Git.Types
 
 data TestOptions = TestOptions
        { tastyOptionSet :: OptionSet
        , keepFailuresOption :: Bool
        , fakeSsh :: Bool
        , concurrentJobs :: Maybe Concurrency
+       , testGitConfig :: [(ConfigKey, ConfigValue)]
        , internalData :: CmdParams
        }
 
index 31c77b0cb28322d36c29daac176cbcb977469ad6..17923cc0260889ff600c5e079e093d8a3ce70fc5 100644 (file)
@@ -30,6 +30,20 @@ framework. Pass --help for details about those.
   When there are test failures, leave the `.t` directory populated with
   repositories that demonstate the failures, for later analysis.
 
+* `--test-git-config name=value`
+
+  The test suite prevents git from reading any git configuration files.
+  Usually it is a good idea to run the test suite with a standard 
+  git configuration. However, this option can be useful to see what
+  effect a git configuration setting has on the test suite. 
+
+  Some configuration settings will break the test suite, in ways that are
+  due to a bug in git-annex. But it is possible that changing a
+  configuration can find a legitimate bug in git-annex.
+
+  One valid use of this is to change a git configuration to a value that
+  is planned to be the new default in a future version of git.
+
 # SEE ALSO
 
 [[git-annex]](1)
index 891fb9c66e0257483e1e9c6e99d632a6e1f4d7ff..78cf7d78f55d84ea83ef398a3bc5aa5860e620da 100644 (file)
@@ -1,5 +1,8 @@
 `git-annex test` prevents ~/.gitconfig or /etc/gitconfig from being read.
+The `-c` option also doesn't propagate into the test suite. 
 
 It would sometimes be useful to test git-annex with a given git config set.
 Although some might break the test suite, others might expose actual bugs
 in git-annex. --[[Joey]]
+
+> Added "--test-git-config" option, [[done]] --[[Joey]]